<?php
/* -------------------------------------------------------------------------------------
* 	ID:						$Id: xajax.additional_text.php 11 2013-09-21 11:43:11Z phone.mueller@googlemail.com $
* 	Letzter Stand:			$Revision: 11 $
* 	zuletzt geaendert von:	$Author: siekiera $
* 	Datum:					$Date: 2013-09-21 11:43:11 +0000 (Sat, 21 Sep 2013) $
*
* 	SEO:mercari by Siekiera Media
* 	http://www.seo-mercari.de
*
* 	Copyright (c) since 2011 SEO:mercari
* --------------------------------------------------------------------------------------
* 	based on:
* 	(c) 2000-2001 The Exchange Project  (earlier name of osCommerce)
* 	(c) 2002-2003 osCommerce - www.oscommerce.com
* 	(c) 2003     nextcommerce - www.nextcommerce.org
* 	(c) 2005     xt:Commerce - www.xt-commerce.com
*
* 	Released under the GNU General Public License
* ----------------------------------------------------------------------------------- */

$xajax->registerFunction('save_new_additional');
$xajax->registerFunction('save_edit_additional');
$xajax->registerFunction('get_additionals_from_db');
$xajax->registerFunction('delete_additional');

function save_new_additional($title, $content, $lng_id, $pID) {
	global $db;
	
	$sql = array('products_id' => $pID,
				'languages_id' => $lng_id,
				'additional_title' => $title,
				'additional_desc' => $content,
				'date_added' => 'NOW()');
	
	$db->db_perform(TABLE_PRODUCTS_ADDITIONAL_TEXT, $sql);

	$ajax = new xajaxResponse();
	$ajax->call('xajax_get_additionals_from_db', $pID, $lng_id);
	$ajax->call('xajax_message', 'Der neue Zusatztext wurde gespeichert', 'success');
		
	return $ajax;
}

function save_edit_additional($title, $content, $lng_id, $pID, $id) {
	global $db;
	
	$ajax = new xajaxResponse();
	
	$sql = array('additional_title' => $title, 'additional_desc' => $content);
		
	$db->db_perform(TABLE_PRODUCTS_ADDITIONAL_TEXT, $sql, 'update', "additional_id = ".$db->db_prepare($id));
	
	$ajax->call('xajax_get_additionals_from_db', $pID, $lng_id);
	$ajax->call('xajax_message', 'Der geänderte Zusatztext wurde gespeichert', 'success');
	
	return $ajax;
}

function get_additionals_from_db($pID, $lng_id) {
	global $db;
	$ajax = new xajaxResponse();
	
	$get_from_db = $db->db_query("SELECT 
										additional_id,
										additional_title,
										additional_desc
									FROM 
										".TABLE_PRODUCTS_ADDITIONAL_TEXT."
									WHERE
										languages_id = '".$lng_id."'
									AND
										products_id = '".$pID."'");
		
	if($get_from_db->_numOfRows) {
		$c = '	<table border="0" width="100%" style="margin-top:10px;border-top: 1px solid #ccc" cellpadding="5">';
		$c .= '		<tr class="dataTableHeadingRow">
            			<td class="dataTableHeadingContent">'.TABLE_HEADING_TITLE.'</td>
            			<td class="dataTableHeadingContent" colspan="2">'.TABLE_HEADING_DESC.'</td>
          			</tr>';
		while(!$get_from_db->EOF) {	$rows++;
			
			if ($rows % 2 == 0)	$f = ' class="dataTableRow"';
			else $f = '';
			
			$c .= '	<tr'.$f.' id="row_'.$get_from_db->fields['additional_id'].'">
						<td>
							<b>'.$get_from_db->fields['additional_title'].'</b>
						</td>
						<td>
							'.substr($get_from_db->fields['additional_desc'], 0, 30).'…
						</td>
						<td align="right">
							<a class="button dialog_button" href="includes/modules/additional_text.php?id='.$get_from_db->fields['additional_id'].'&lng='.$lng_id.'&action=edit">
								'.BUTTON_EDIT.'
							</a> 
							<button class="button" type="button" onclick="xajax_delete_additional('.$get_from_db->fields['additional_id'].')">'.BUTTON_DELETE.'</button>
						</td>
					</tr>';
			$get_from_db->MoveNext();
		}
		$c .= '</table>';
	}
		
	$ajax->assign('addition_text_container', 'innerHTML', $c);
	
	return $ajax;
}

function delete_additional($id) {
	global $db;
	
	$ajax = new xajaxResponse();
	
	$db->db_query("DELETE FROM ".TABLE_PRODUCTS_ADDITIONAL_TEXT." WHERE additional_id = '".$id."'");
	
	$ajax->script('$("#row_'.$id.'").fadeOut(800, function(){$(this).remove()})');
	
	$ajax->call('xajax_message', 'Der Zusatztext wurde gelöscht', 'warning');
	
	return $ajax;
}
?>